﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Clmp.Data.DBEntity
{
    public class Entity
       //where TEntityType : IEntity
    {
        /// <summary>
        /// 属性字典，键对应数据库的列名，值对应相应的属性值。
        /// </summary>
        protected Dictionary<string, object> PropertyDictionary;

        internal Dictionary<string, object> GetPropertyDictionary()
        {
            return PropertyDictionary;
        }

        public Entity()
        {
            PropertyDictionary = new Dictionary<string, object>();
        }
        /// <summary>
        /// 获取属性值
        /// </summary>
        /// <param name="columnName">数据库列名</param>
        /// <returns>对应的属性值</returns>
        internal object GetPropertyValue(string columnName)
        {
            object value;
            if (PropertyDictionary.TryGetValue(columnName, out value))
            {
                return value;
            }
            return null;
        }
        /// <summary>
        /// 获取属性值
        /// </summary>
        /// <typeparam name="T">返回类型</typeparam>
        /// <param name="columnName">数据库列名</param>
        /// <returns>对应的属性值</returns>
        internal T GetPropertyValue<T>(string columnName)
        {
            object value = GetPropertyValue(columnName);
            if (value != null)
            {
                return (T)value;
            }
            return default(T);
        }
        /// <summary>
        /// 设置属性值
        /// </summary>
        /// <param name="columnName">数据库列名</param>
        /// <param name="value">要设置的值</param>
        internal void SetPropertyValue(string columnName, object value)
        {
            PropertyDictionary[columnName] = value;
        }

        public void RemoveColumnUpdate(string columnName)
        {
            PropertyDictionary.Remove(columnName);
        }
    }
}
